#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+5,mod = 1e9+7,inv2 = (mod+1)>>1;
int n,son[N],mx[N];
vector<int> g[N];
void dfs1(int u)
{
	son[u] = -1;
	for(auto v:g[u])
	{
		dfs1(v);
		if(mx[v]+1>mx[u]) mx[u] = mx[v]+1,son[u] = v;
	}
}
int tmp[N<<1],*f[N],*now = tmp+1,tag[N];
inline int qpow(int x,int y)
{
	int res = 1;
	while(y)
	{
		if(y&1) res = res*x%mod;
		y>>=1;
		x = x*x%mod;
	}
	return res;
}
void dfs2(int u)
{
	if(son[u]!=-1)
	{
		f[son[u]] = f[u]+1;
		dfs2(son[u]);
	}
	int lim = 0;
	for(auto v:g[u])
	{
		if(v==son[u]) continue;
		f[v] = now,now+=mx[v]+1;
		dfs2(v);
		lim = max(lim,mx[v]+1);
	}
	for(int i = 0;i<=lim;i++) tag[i] = (1-f[u][i]+mod)%mod,f[u][i] = f[u][i]*qpow(1-f[u][i]+mod,mod-2)%mod;
	for(auto v:g[u])
	{
		if(v==son[u]) continue;
		for(int i = 0;i<=mx[v];i++) (f[u][i+1]+=f[v][i]*qpow(1-f[v][i]+mod,mod-2))%=mod;
	}
	for(auto v:g[u])
	{
		if(v==son[u]) continue;
		for(int i = 0;i<=mx[v];i++) (tag[i+1]*=1-f[v][i]+mod)%=mod;
	}
	for(int i = 0;i<=lim;i++) f[u][i] = f[u][i]*tag[i]%mod;
	f[u][0] = inv2;
}
signed main()
{
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i = 1,x;i<=n;i++)
		cin>>x,g[x].push_back(i);
	dfs1(0);
	f[0] = now,now+=mx[0]+1;
	dfs2(0);
	int ans = 0;
	for(int i = 0;i<=mx[0];i++)
		(ans+=f[0][i])%=mod;
	cout<<ans*qpow(2,n+1)%mod;
	return 0;
}

